package lagou.homework.lagou_homework_rocketmq.controller;

import lagou.homework.lagou_homework_rocketmq.entity.Goods;
import lagou.homework.lagou_homework_rocketmq.repository.GoodsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("goods")
public class GoodsController {
    @Autowired
    private GoodsRepository goodsRepository;

    /**
     * 加载全部商品
     * @return
     */
    @RequestMapping("/list")
    public ModelAndView list(){
        ModelAndView mv = new ModelAndView();
        List<Goods> goods = goodsRepository.findAll();
        mv.addObject("goodsList",goods);
        mv.setViewName("goods_list");
        return mv;
    }
}
